import pygame_sprite


class Group(pygame_sprite.Group):
	"""Sprite group which also maintains an index of contained sprites.

	Contained sprites must have an attribute named "id" which is what the
	indexed is keyed by.
	"""

	def __init__(self, *args):
		pygame_sprite.Group.__init__(self, *args)
		self._index = {}

	def get(self, *args):
		return self._index.get(*args)

	def add_internal(self, sprite):
		pygame_sprite.Group.add_internal(self, sprite)
		self._index[sprite.id] = sprite

	def remove_internal(self, sprite):
		del self._index[sprite.id]
		pygame_sprite.Group.remove_internal(self, sprite)

	def has_internal(self, id_or_sprite):
		if self._index.has_key(id_or_sprite):
			return True
		return pygame_sprite.Group.has_internal(self, id_or_sprite)


class GroupSingle(pygame_sprite.GroupSingle):
	"""Sprite group which passes attribute access through to the single
	contained sprite.
	"""

	def __getattr__(self, name):
		return getattr(self.__sprite, name)

	#def __setattr__(self, name, value):
	#	self.__sprite.__dict__[name] = value


class Sprite(pygame_sprite.Sprite):
	"""Base sprite class.
	"""
	pass

